#include <iostream>
#include <cstring>

// 结构体做参数
void printBook(struct Books book);
void printBook2(struct Books *book);

using namespace std;

typedef long int *pint32;

typedef struct Books2
{
    char title[50];
    char author[50];
    char subject[100];
    int book_id;
} Books_typedef;

// 声明一个结构体类型 Books
struct Books
{
    char title[50];
    char author[50];
    char subject[100];
    int book_id;
} Book3;

int main()
{
    Books Book1; // 定义结构体类型 Books 的变量 Book1
    Books Book2; // 定义结构体类型 Books 的变量 Book2

    // Book1 详述
    strcpy(Book1.title, "C++ 教程");
    strcpy(Book1.author, "过往");
    strcpy(Book1.subject, "编程语言");
    Book1.book_id = 12345;

    // Book2 详述
    strcpy(Book2.title, "CSS 教程");
    strcpy(Book2.author, "过往");
    strcpy(Book2.subject, "前端技术");
    Book2.book_id = 12346;

    // Book3 详述
    strcpy(Book3.title, "后端");
    strcpy(Book3.author, "过往");
    strcpy(Book3.subject, "哈哈");
    Book3.book_id = 12347;

    // 输出 Book1 信息
    cout << "第一本书标题 : " << Book1.title << endl;
    cout << "第一本书作者 : " << Book1.author << endl;
    cout << "第一本书类目 : " << Book1.subject << endl;
    cout << "第一本书 ID : " << Book1.book_id << endl;

    // 输出 Book2 信息
    cout << "第二本书标题 : " << Book2.title << endl;
    cout << "第二本书作者 : " << Book2.author << endl;
    cout << "第二本书类目 : " << Book2.subject << endl;
    cout << "第二本书 ID : " << Book2.book_id << endl;

    // 输出 Book3 信息
    printBook(Book3);

    // 结构体指针
    struct Books *struct_pointer;

    struct_pointer = &Book3;

    cout << "指针: " << struct_pointer->title << endl;

    printBook(*struct_pointer);

    printBook2(struct_pointer);
    printBook2(&Book2);

    return 0;
}

void printBook(struct Books book)
{
    cout << "书标题 : " << book.title << endl;
    cout << "书作者 : " << book.author << endl;
    cout << "书类目 : " << book.subject << endl;
    cout << "书 ID : " << book.book_id << endl;
}

void printBook2(struct Books *book)
{
    cout << "书标题  : " << book->title << endl;
    cout << "书作者 : " << book->author << endl;
    cout << "书类目 : " << book->subject << endl;
    cout << "书 ID : " << book->book_id << endl;
}
